Skip to content

Remove legacy decorators - #927

Merged
craigbarratt merged 9 commits into
custom-components:masterfrom
dmamelin:remove-legacy-decorators
Nov 24, 2026
Merged

craigbarratt merged 9 commits into
custom-components:masterfrom
dmamelin:remove-legacy-decorators

Conversation

@dmamelin

@dmamelin dmamelin commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Removes the legacy decorator subsystem (legacy_decorators: true).

Changes

  • legacy_decorators option removed. If it's still in configuration.yaml, it's dropped with an error in the log (cv.removed) and the config stays valid. Config entries are migrated to 1.2, which drops the key from entry.data (for entries set up from the UI).
  • trigger.py, event.py, mqtt.py and webhook.py removed. What is still used moved almost unchanged:
    • TrigTime (time specs for @time_trigger / @time_active) → decorators/timing.py
    • ident_*, strip_trigger_expr, any_trigger_exprs → decorators/state.py
    • dt_now → decorator_abc.py
    • task.create, task.add_done_callback, task.executor → new task_functions.py (see below)
  • Of trigger_init, only the logger / global_ctx_name switch is kept, so a function wrapped by a decorator from a module still logs under the script that defines it.
  • Kwargs that are ignored because they are in TRIGGER_KWARGS now log a warning, once per function definition (Unexpected keyword arguments are silently ignored when their names are in TRIGGER_KWARGS #905). A common case is a wrapper that passes all its **kwargs on to a function that doesn't declare them; in Python that's a TypeError.
  • Fixed the watchdog startup/shutdown event annotations.
  • Docs updated.
  • Added mqtt to after_dependencies in the manifest. hassfest accepted the mqtt import only because of the old mqtt.py, which it treated as an mqtt platform of pyscript.
  • The follow-up from Fix keyword argument collisions in pyscript function calls #926: the internal parameters of task.create, task.executor, task.add_done_callback, service.call and event.fire are now positional-only, so keywords like func, domain, name or event_type go to the called function, the service data or the event data.

The commits are split for review; the moves are separate from the changes. The moved code is kept almost as it was, so it's easy to compare with the old trigger.py: TrigTime.init is now called from the time decorators' validate(), and the task.* closures became TaskFunctions methods. The code could use some cleanup and reorganization (for example, TrigTime itself), but that's out of scope for this PR.

task_functions.py

task.create, task.add_done_callback and task.executor were registered in TrigTime.init, which wasn't a good place for them: TrigTime handles time specs. They were there only because they need AstEval / EvalFunc / EvalFuncVar, and function.py can't import eval.py (eval.py imports function.py). I kept your pattern: Function doesn't depend on eval, and modules that need eval register their own functions, like State.register_functions(). So they are now in a TaskFunctions class with register_functions().

The other task.* functions (sleep, cancel, current_task, wait, remove_done_callback, unique, name2id) are still in Function. Would you like all task.* functions in one place? If so, I'd do that in a separate PR. task.unique and task.name2id use Function internals (unique_name_used, and TaskUniqueDecorator calls task_unique_factory), so they may be better left where they are.

@craigbarratt

Copy link
Copy Markdown
Member

Thanks @dmamelin. This is for the release after the next one, right?

hassfest accepted the mqtt import only because of the legacy mqtt.py
file, which it treated as an mqtt platform of pyscript.
…ional-only

Follow-up to custom-components#926: keyword arguments such as func, task, callback, domain,
name or event_type are now passed on to the called function, the service
data or the event data, instead of clashing with the parameters of
task.create, task.executor, task.add_done_callback, service.call and
event.fire.
@dmamelin
dmamelin force-pushed the remove-legacy-decorators branch from f37926d to 74c17d2 Compare November 24, 2026 20:15
@dmamelin

Copy link
Copy Markdown
Contributor Author

Added the follow-up from #926: the internal parameters of task.create, task.executor, task.add_done_callback, service.call and event.fire are now positional-only, so keywords like func, domain, name or event_type go to the called function, the service data or the event data. state.set() can't be fixed this way without changing its API (value is a keyword parameter there).

@dmamelin

Copy link
Copy Markdown
Contributor Author

@craigbarratt about the release: when I suggested releasing 2.2.0 right after #899, I didn't expect so much to land in between. There are now 52 commits on master since 2.1.1 (#870 through #926), so a release with only the new @service no longer makes sense. I'd merge #927 first and release everything together.

@craigbarratt

Copy link
Copy Markdown
Member

Yes, we are in the world of AI PRs and issues, and I'm using AI to try to keep up.

I agree with your approach. It's a major release already. Please tell me when you think this PR is ready for review.

@dmamelin

Copy link
Copy Markdown
Contributor Author

This PR is ready for review; there were only some technical issues. Since I opened it, I rebased it on #926 and added two commits: mqtt in after_dependencies for hassfest, and the positional-only follow-up from #926 (task.*, service.call, event.fire). The PR description is updated.

I don't think we should release before #925 is fixed, though. The bug is rare, but completely silent: the script keeps running with the wrong values and nothing is logged.

Over the next few days I'll try to look into the AI-written code during my coffee breaks.

@craigbarratt craigbarratt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmamelin, this is a big cleanup, and splitting the moves from the changes made it easy to review. I compared every definition that moved out of trigger.py with the original. Apart from the dropped legacy wait_until, the init changes and dt_now, they're identical, and the task.* functions moved unchanged. The config entry migration and cv.removed look right.

I also checked task.create, task.add_done_callback, task.executor, service.call and event.fire with colliding keywords, and the #905 warning through a **kwargs wrapper (logged once per function), and they all behave as described.

One thing for a follow-up: several comments still say to change something once the legacy subsystem is removed (decorator_abc.py 88 and 268, decorators/service.py 113–117, plus the "Keep this wording for transition compatibility" in decorators/state.py 101 and decorators/timing.py 450). Now's the time to update those messages and tests, or drop the comments. That includes the @service reserved-name check, which still doesn't look at the domain.

@dmamelin

Copy link
Copy Markdown
Contributor Author

Thanks @craigbarratt for the review! I left those messages and comments on purpose, to keep this PR from growing.

I have another PR in progress that points decorator errors at their exact location in the script, and it already includes updating these legacy messages. It was almost ready; I'll start adapting it to #921 soon, which will probably need significant changes.

The messages don't affect behaviour, so if there are no other comments, this can be merged now.

@craigbarratt

Copy link
Copy Markdown
Member

Thanks @dmamelin; merging now.

@craigbarratt
craigbarratt merged commit b32fcfa into custom-components:master Nov 24, 2026
6 checks passed
@dmamelin
dmamelin deleted the remove-legacy-decorators branch November 25, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants